From 793bbc7a7f62c953b9437bd716980fe608debec8 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 12 Dec 2001 06:40:08 +0000 Subject: [PATCH] add another example 2001-12-12 Havoc Pennington * gtk/text_widget.sgml: add another example --- docs/reference/ChangeLog | 4 ++ docs/reference/gtk/text_widget.sgml | 66 ++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 74771db949..40434b6bd8 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2001-12-12 Havoc Pennington + + * gtk/text_widget.sgml: add another example + 2001-12-09 Matthias Clasen * gtk/tmpl/gtkmain.sgml: Markup fixes. diff --git a/docs/reference/gtk/text_widget.sgml b/docs/reference/gtk/text_widget.sgml index 42d5525e29..3c785254a3 100644 --- a/docs/reference/gtk/text_widget.sgml +++ b/docs/reference/gtk/text_widget.sgml @@ -127,7 +127,7 @@ might look like this: buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - gtk_text_buffer_set_text (buffer, "Hello, this is some text"); + gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1); /* Now you might put the view in a container and display it on the * screen; when the user edits the text, signals on the buffer @@ -143,4 +143,68 @@ gtk_text_view_set_buffer(). + +Example of Changing Text Attributes + + + +There are two ways to affect text attributes in +GtkTextView. +You can change the default attributes for a given +GtkTextView, and you can +apply tags that change the attributes for a region of text. +For text features that come from the theme — such as +font and foreground color &mdash use standard +GtkWidget +functions such as +gtk_widget_modify_font() +or +gtk_widget_modify_fg(). +For other attributes there are dedicated methods on +GtkTextView such as +gtk_text_view_set_tabs(). + + + GtkWidget *view; + GtkTextBuffer *buffer; + PangoFontDescription *font_desc; + GdkColor color; + GtkTextTag *tag; + + view = gtk_text_view_new (); + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + + gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1); + + /* Change default font throughout the widget */ + font_desc = pango_font_description_from_string ("Serif 15"); + gtk_widget_modify_font (view, font_desc); + pango_font_description_free (font_desc); + + /* Change default color throughout the widget */ + gdk_color_parse ("green", &color); + gtk_widget_modify_fg (view, GTK_STATE_NORMAL, &color); + + /* Change left margin throughout the widget */ + gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 30); + + /* Use a tag to change the color for just one part of the widget */ + tag = gtk_text_buffer_create_tag (buffer, "blue_foreground", + "foreground", "blue", NULL); + gtk_text_buffer_get_iter_at_offset (buffer, &start, 7); + gtk_text_buffer_get_iter_at_offset (buffer, &end, 12); + gtk_text_buffer_apply_tag (buffer, tag, &start, &end); + + + + + +The gtk-demo application that comes with +GTK+ contains more example code for GtkTextView. + + + + -- 2.30.2